{% extends 'marketing/base.html' %}
{% load static %}
{% load paginate %}
{% block content %}
{{ block.super }}
<div class="main_container ml-5 mr-5">
  <div class="row marl">

    <div class="filter_row list_filter_row row marl col-md-12 mb-2">
      <div class="">
        <div class="card">
          <div class="card-body">
            <form id="leads_filter" action="" method="POST">
              <div class="card-body ">
                <div class="card-title">Filters</div>
                <div class="row marl">
                  <div class="filter_col col-md-3">
                    <div class="form-group">
                      <label for="exampleInputEmail1">Name</label>
                      <input type="text" class="form-control" placeholder="Template Name" name="template_name"
                        value="{{request.POST.template_name}}">
                    </div>
                  </div>
                  <div class="filter_col col-md-3">
                    <div class="form-group">
                      <label for="exampleInputEmail1">Created By</label>
                      <select name="created_by" id="created_by" class="assigned_users_ form-control">
                        <option value="">
                          ------------------</option>
                        {% for user in users %}
                        <option value="{{user.id}}" {% if user.id|slugify == request.POST.created_by %} selected=""
                          {% endif %}>
                          {{user.email}}</option>
                        {% endfor %}
                      </select>
                    </div>
                  </div>
                  <input type="hidden" name="tab_status" id="tab_status">
                  <div class="filter_col col-2">
                    <div class="form-group buttons_row">
                      <button class="btn btn-primary save" type="submit">Search</button>
                      <a href="" class="btn btn-default clear" onclick="window.location.reload">Clear</a>
                    </div>
                  </div>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>

    <div class="col-md-12">
      <div class="table_container_row no_mar_top">
        <div class="card">
          <div class="card-body">
            <div class="card-title text-right">
              <span class="float-left">Email Templates - {{email_templates|length}}</span>
              <span class="filter_toggle">
                <a href="#" class="primary_btn"><i class="fas fa-filter"></i></a>
              </span>
              <a href="{% url 'marketing:email_template_new' %}" class="primary_btn">Add New Email Template</a>
            </div>
            <div class="table-responsive table-bordered ">
              <table class="table">
                {% if email_templates %}
                <thead>
                  <tr>
                    <th width="5%" class="text-center">S. No</th>
                    <th width="20%" class="text-center">Template Name</th>
                    <th width="15%" class="text-center">Created By</th>
                    <th width="10%" class="text-center">Created On</th>
                    <th width="10%" class="text-center">Create Campaign</th>
                    
                    <th width="15%" class="text-center">Actions</th>
                  </tr>
                </thead>
                {% endif %}
                <tbody>
                  {% if per_page %}
                  {% paginate per_page email_templates %}
                  {% else%}
                  {% paginate 10 email_templates %}
                  {% endif %}
                  {% for email_template in email_templates %}
                  <tr style="text-align:center;">
                    <td class="text-center" scope="row">{{ forloop.counter }}</td>
                    <td scope="row"><a
                        href="{% url 'marketing:email_template_detail' email_template.id %}">{{ email_template.title }}</a>
                    </td>
                    <td scope="row">{{ email_template.created_by }}</td>
                    <td scope="row" title="{{ email_template.created_on }}">{{ email_template.created_on_arrow }}</td>
                    <td class="text-center"><a
                        href="{% url 'marketing:create_campaign_from_template' email_template.id %}" class="a_color"
                        data-toggle="tooltip" data-placement="bottom"
                        title="Create a new campaign with this template"><i class="fas fa-calendar-plus"></i></a></td>
                    
                    <td class="actions text-center">
                      <a href="{% url 'marketing:email_template_detail' email_template.id %}"
                        class="btn btn-info edit" title="View" ><i class="fas fa-eye"></i></a>
                      <a href="{% url 'marketing:email_template_edit' email_template.id %}"
                        class="btn btn-success edit" title="Edit" ><i class="fas fa-edit"></i></a>
                      <a href="{% url 'marketing:email_template_delete' email_template.id %}"
                        class="btn btn-danger delete remove_account" title="Delete"><i class="fas fa-trash"></i></a>
                    </td>
                  </tr>
                  {% empty %}
                  <tr>
                    <td colspan="4">No Records Found!</td>
                  </tr>
                  {% endfor %}
                  

                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="marl row text-center mt-5">
    {% show_pages %}
  </div>
</div>
{% endblock %}
{% block js_block %}
<script>
  $(function () {
    $('[data-toggle="tooltip"]').tooltip()
    $(".filter_toggle").click(function () {
      $(".list_filter_row").toggle();
    });

    search = "{{search}}"
    alert(search)
    if (search == 'True') {
    $(".list_filter_row").show();
    }

    $('#id_tag').select2();
    $('#created_by').select2();

    $(".remove_account").click(function (e) {
      e.preventDefault()
      url = $(this).attr('href')
      if (!confirm('Are you sure you want to delete?'))
        return;
      window.location = $(this).attr('href')
    })

    $("a[rel='page']").click(function (e) {
      e.preventDefault();
      $('#leads_filter').attr("action", $(this).attr("href"));
      $('#leads_filter').submit();
    });
  })
</script>
{% endblock js_block %}